using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityUtilities;

public class time : MonoBehaviour
{
    private float delay = 0;
    public int alltime = 100;
    private float interval = 0;
    private int currentScend;
    private Countdown countdown;
    public state player1;
    public state player2;
    private void Awake()
    {
        countdown = new Countdown(false, alltime);
    }
    // Start is called before the first frame update
    void Start()
    {
        currentScend = alltime;
        this.gameObject.GetComponent<Text>().text = currentScend.ToString();
    }

    // Update is called once per frame
    void Update()
    {
        if (!countdown.Progress())
        {
            interval += Time.deltaTime;

            if (interval > 1)
            {
                currentScend--;
                this.gameObject.GetComponent<Text>().text=currentScend.ToString();
                interval = 0;
            }

        }
        else
        {
            currentScend--;
            this.gameObject.GetComponent<Text>().text = currentScend.ToString();

            Time.timeScale = 0;
            if (player1.health > player2.health)
            {
                this.gameObject.GetComponent<Text>().text = "Player1 WIN!";
            }
            else if(player1.health < player2.health)
            {
                this.gameObject.GetComponent<Text>().text = "Player2 WIN!";
            }
            else
            {
                this.gameObject.GetComponent<Text>().text = "平局";
            }
        }
    }
}
